package com.last1mile.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.last1mile.model.Login;

@Component("loginValidator")
public class LoginValidator implements Validator {

    @Override
    public boolean supports(Class<?> clazz) {
        return Login.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object target, Errors errors) {
        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginId", "required.loginID", "Field name is required.");

        ValidationUtils.rejectIfEmptyOrWhitespace(errors, "loginPwd", "required.loginPassword",
                                                  "Field name is required.");

    }
}
